home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
cpp_libs
/
rjs.lha
/
RJS
/
CmdLine
/
src
/
CmdLine.h
< prev
next >
Wrap
C/C++ Source or Header
|
1991-06-14
|
5KB
|
173 lines
#ifndef RJS_CMDLINE_CLASS_H
#define RJS_CMDLINE_CLASS_H
#include<RJS/String.h>
class RJS_CmdOpt {
friend class RJS_CmdLine;
public:
enum CmdOptFlags {
None=0x00, // no flags
Value=0x01, // value needed
ValueOpt=0x02, // value is optional
Required=0x04, // this option required!
Default=0x08, // has default value
Parameter=0x10 // parameter, not -flag (not done)
};
enum CmdPresFlags {
NotPresent=0x00, // option not specified
Present=0x01, // option present
DefaultValue=0x02, // default value was taken
ValuePresent=0x04 // value was present (for ValueOpt)
};
RJS_CmdOpt(const char *k, CmdOptFlags f=None);
RJS_CmdOpt(const char *k, const RJS_String &defval,CmdOptFlags f=None);
int not_present() { return present==NotPresent; }
int is_present() { return present; }
int is_default() { return present & DefaultValue; }
int value_present() { return present & ValuePresent; }
int expects_value() { return flags & Value; }
int is_required() { return flags & Required; }
int value_optional() { return flags & ValueOpt; }
int has_default() { return flags & Default; }
const RJS_String &keyword() { return key; }
const RJS_String &value() { return val; }
const RJS_String &default_value() { return dval; }
virtual const char *value_type();
int set(const char *s);
int set_default();
void set();
virtual void reset();
virtual void dump();
protected:
int virtual set_value();
RJS_String key;
int abbrev_len;
CmdOptFlags flags;
CmdPresFlags present;
RJS_String val;
RJS_String dval;
};
class RJS_CmdOpt_flag : public RJS_CmdOpt {
public:
RJS_CmdOpt_flag(const char *k) : RJS_CmdOpt(k,None) {};
};
class RJS_CmdOpt_boolean : public RJS_CmdOpt {
public:
RJS_CmdOpt_boolean(const char *k, CmdOptFlags f=None);
RJS_CmdOpt_boolean(const char *k, const RJS_String &dv, CmdOptFlags f=None);
int value() { return val; }
const char *value_type();
virtual void reset();
virtual void dump();
private:
int set_value();
int val;
};
class RJS_CmdOpt_double : public RJS_CmdOpt {
public:
RJS_CmdOpt_double(const char *k, CmdOptFlags f=None);
RJS_CmdOpt_double(const char *k, const RJS_String &dv,CmdOptFlags f=None);
double value() { return val;}
const char *value_type();
virtual void reset();
virtual void dump();
private:
int set_value();
double val;
};
class RJS_CmdOpt_int : public RJS_CmdOpt {
public:
RJS_CmdOpt_int(const char *k, CmdOptFlags f=None);
RJS_CmdOpt_int(const char *k, const RJS_String &df, CmdOptFlags f=None);
int value() { return val; }
const char *value_type();
virtual void dump();
virtual void reset();
private:
int set_value();
int val;
};
class RJS_CmdOpt_string : public RJS_CmdOpt {
public:
RJS_CmdOpt_string(const char *k, CmdOptFlags f=None);
RJS_CmdOpt_string(const char *k, const RJS_String &df, CmdOptFlags f=None);
};
class RJS_CmdOpt_int_range : public RJS_CmdOpt {
public:
RJS_CmdOpt_int_range(const char *k, CmdOptFlags f=None);
RJS_CmdOpt_int_range(const char *k, const RJS_String &df,CmdOptFlags f=None);
int low_value() { return lval; }
int low_is_present() { return l_present; }
int high_value() { return hval; }
int high_is_present() { return h_present; }
const char *value_type();
void reset();
virtual void dump();
private:
int set_value();
int lval;
int hval;
RJS_CmdOpt::CmdPresFlags l_present;
RJS_CmdOpt::CmdPresFlags h_present;
};
class RJS_CmdLineWord {
public:
RJS_CmdLineWord( char **argv);
RJS_CmdLineWord( RJS_String &s, int dcl);
~RJS_CmdLineWord();
int operator() (RJS_String &word);
int peek(RJS_String &word);
private:
RJS_StringScan *scan;
char **argv;
int peek_flag;
RJS_String peeked;
};
class RJS_CmdLine {
public:
enum CmdLineFlags {
Abort=0x01,
Messages=0x02,
Once=0x04,
Abbrev=0x08,
NoCase=0x10,
DCL=0x20
};
enum ParseStatus { Ok, UnknownOption, BadValue, NoValue,MissingRequired,
MoreThenOnce};
RJS_CmdLine(RJS_CmdOpt **options, const char *p,
CmdLineFlags flags=CmdLineFlags(Abort|Messages|Abbrev));
ParseStatus parse(char **argv, RJS_String &xtra);
ParseStatus parse(RJS_String &cmdline, RJS_String &xtra);
ParseStatus parse(RJS_CmdLineWord &clw, RJS_String &xtra);
void dump();
only_once() { return flags & Once; }
abort() { return flags & Abort; }
messages() { return flags & Messages; }
dcl () { return flags & DCL; }
abbrev() { return flags & Abbrev; }
no_case() { return flags & NoCase; }
RJS_String &last_opt() { return opt; }
RJS_String &last_val() { return val; }
private:
void setup_abbrevs();
const char *prefix; // prefix for messages
CmdLineFlags flags;
RJS_String opt,val; // last option worked on
RJS_CmdOpt **options;
char sep; // seperator '-' for Unix, '/' for DCL
};
#endif